from code.unit.master import UnitMaster
from code.price.master import Deal, view as deal_view
from code.velocity import master as velocity
import unittest

class VelocityTest(unittest.TestCase):
    def test_view(self):
        self.assertEqual(5, velocity.view('hello'))
        self.assertEqual(3, velocity.view(''))

    def test_post(self):
        self.assert_(velocity.post('thumb.py').index('thumb.py'))

    def test_now(self):
        self.assert_(velocity.clock())

class UnitMasterTest(unittest.TestCase):
    def setUp(self):
        self.m = UnitMaster()

    def test_init(self):
        self.assertEqual(len(self.m.init()), 3)

    def test_ratio_normal(self):
        self.assertEqual(2, self.m.ratio(4, 2))

    def test_ratio_base_0(self):
        self.assertEqual(0, self.m.ratio(4, 0))

class DealTest(unittest.TestCase):
    def setUp(self):
        self.d = Deal()

    def test_get_absolute_url(self):
        self.assertEqual('/deals/thumb.py', self.d.get_absolute_url())

    def test_get_display_name(self):
        from code.price.master import DEAL_PAYMENT, DEAL_DEPOSIT, DEAL_CHECK
        self.assertEqual('Payment', self.d.get_display_name(DEAL_PAYMENT))
        self.assertEqual('Deposit', self.d.get_display_name(DEAL_DEPOSIT))
        self.assertEqual('Check', self.d.get_display_name(DEAL_CHECK))

    def test_view(self):
        self.assertEqual(3, deal_view(3))
        self.assertEqual(0, deal_view(5))

